package com.yizhang.pattern.strategy;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: yi.zhang
 * @CreateTime: 2025-08-21 16:37:17
 * @Description:
 */
public class Order {

    private static final String JD_PAY = "jd";
    private static final String WECHAT_PAY = "wechat";
    private static final Map<String, Class<? extends Payment>> paymentMap = new HashMap<>();

    static {
        paymentMap.put(JD_PAY, JdPay.class);
        paymentMap.put(WECHAT_PAY, WeChatPay.class);
    }

    public void createOrder(String type) throws InstantiationException, IllegalAccessException {
        Class<? extends Payment> pay = paymentMap.get(type);
        Payment payment = pay.newInstance();
        System.out.println(payment.getAmount());
        payment.pay();
        System.out.println(payment.getAmount());
    }
}
